package com.group18.service;

import java.util.List;

import com.group18.dao.AccountUserDao;
import com.group18.entity.AccountUser;




/**
 * PhoneUser service类 调用dao类
 * @author Nicky
 *
 */
public class AccountUserService {

	private AccountUserDao userDao = new AccountUserDao();
	
	/**
	 * 模糊搜索方法
	 * @param name
	 * @return
	 */
	public List<AccountUser> SelectAccountByText(String text) {
		return userDao.SelectAccountByText(text);
	}
	
	/**
	 * 根据家庭id查询家庭的所有收支和支出
	 * @param family
	 * @return
	 */
	public int selectAccountByFamily_id(int family_id) {
		return userDao.selectAccountByFamily_id(family_id);
	}
	
	/**
	 * 删除某个家庭成员所有收支
	 * @param member_id
	 * @return
	 */
	public int deleteAccountByMember_id(int member_id) {
		return userDao.deleteAccountByMember_id(member_id);
	}
	
	/**
	 * 根据用户名查询id
	 * @param u
	 * @return
	 */
//	public int selectIdByUsername(AccountUser u) {
//		return userDao.selectIdByUsername(u);
//	}
	
	/**
	 * 修改收支记录人
	 * @param u
	 * @return
	 */
	public int updateAccountUsername(AccountUser u) {
		return userDao.updateAccountUsername(u);
	}
	
	/**
	 * 添加收支
	 * @param pu
	 * @return 返回修改数据库条数 0 失败 1成功
	 */
	public int addAccount(AccountUser u){
		return userDao.addAccount(u);
	}
	
	/**
	 * 修改用户数据
	 * @param u
	 * @return
	 */
	public int upDate(AccountUser u) {
		return userDao.upDataAccount(u);
	}
	
	/**
	 * 判断用户名密码对应的数据是否存在
	 * @param pu
	 * @return 返回 true 存在， false不存在
	 */
	public boolean isExist(AccountUser u){
		return userDao.isExist(u);
	}
	
	/**
	 * 标签图标的class属性
	 * @param label
	 * @return
	 */
	public String classStr(String label) {
		String classStr = "";
		if(label.equals("学习")) {
			classStr = "fa fa-graduation-cap";
		}else if(label.equals("吃喝")) {
			classStr = "fa fa-cutlery";
		}else if(label.equals("交通")) {
			classStr = "fa fa-bus";
		}else if(label.equals("医疗")) {
			classStr = "fa fa-plus-square";
		}else if(label.equals("购物")) {
			classStr = "fa fa-shopping-bag";
		}else if(label.equals("电子产品")) {
			classStr = "fa fa-mobile fa-lg";
		}else if(label.equals("娱乐")) {
			classStr = "fa fa-gamepad";
		}else if(label.equals("化妆护肤")) {
			classStr = "fa fa-magic";
		}else if(label.equals("工资")) {
			classStr = "fa fa-credit-card";
		}else if(label.equals("兼职")) {
			classStr = "fa fa-clock-o";
		}else if(label.equals("投资")) {
			classStr = "fa fa-balance-scale";
		}else if(label.equals("红包")) {
			classStr = "fa fa-envelope-o";
		}else if(label.equals("其他")) {
			classStr = "fa fa-database";
		}
		return classStr;
	}
	
	/**
	 * 设置标签图表背景颜色class属性
	 * @param label
	 * @return
	 */
	public String background(String label) {
		String background = "";
		if(label.equals("学习")) {
			background = "yellow-bg";
		}else if(label.equals("吃喝")) {
			background = "yellow-bg";
		}else if(label.equals("交通")) {
			background = "blue-bg";
		}else if(label.equals("医疗")) {
			background = "red-bg";
		}else if(label.equals("购物")) {
			background = "red-bg";
		}else if(label.equals("电子产品")) {
			background = "lazur-bg";
		}else if(label.equals("娱乐")) {
			background = "navy-bg";
		}else if(label.equals("化妆护肤")) {
			background = "red-bg";
		}else if(label.equals("工资")) {
			background = "navy-bg";
		}else if(label.equals("兼职")) {
			background = "blue-bg";
		}else if(label.equals("投资")) {
			background = "lazur-bg";
		}else if(label.equals("红包")) {
			background = "red-bg";
		}else if(label.equals("其他")) {
			background = "white-bg";
		}
		return background;
	}
	
	/**
	 * 查询家庭所有收支
	 * @return
	 */
	public List<AccountUser> selectAllAccountByFamily_id(AccountUser u){
		return userDao.selectAllAccountByFamily_id(u);
	}
	
	/**
	 * 删除某个家庭的所有收支
	 * @param family_id	家庭id
	 * @return
	 */
	public int deleteAccountByFamily_id(int family_id) {
		return userDao.deleteAccountByFamily_id(family_id);
	}
	
	/**
	 * 删除收支
	 * @param id	要删除的id
	 * @return		是否删除成功
	 */
	public boolean deleteByID(int id) {
		boolean flag = false;
		int i = userDao.deleteByID(id);
		if(i > 0) {
			flag = true;
		}
		return flag;
	}
	
}
